/*
 * Copyright 2013 JROSE
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jrose.entity.data;

import lombok.Getter;
import lombok.Setter;
import org.jrose.api.annotation.cache.CacheExpiration;
import org.jrose.api.annotation.persistence.Column;
import org.jrose.api.annotation.persistence.Table;
import org.jrose.entity.common.AbstractDatabaseEntity;
import org.jrose.entity.constant.UserStatus;
import org.jrose.entity.constant.UserType;

/**
 * User data structure.
 *
 * @author Xiaohai Zhang
 * @since 2013-08-23 18:12
 */
@Table("JROSE_USER")
@CacheExpiration
public class User extends AbstractDatabaseEntity {
    private static final long serialVersionUID = 3326921642096567995L;

    @Getter @Setter @Column(defaultValue = @Column.DefaultValue("NEONATAL")) private UserStatus userStatus;
    @Getter @Setter @Column(defaultValue = @Column.DefaultValue("ANONYMOUS")) private UserType userType;
    @Getter @Setter @Column(notNull = true) private String username;
    @Getter @Setter @Column(notNull = true) private String password;
    @Getter @Setter @Column(notNull = true) private String salt;
    @Getter @Setter @Column(notNull = true) private String plainPassword;

    @Getter @Setter private Team team;

    // static factory method:

    public static User newInstance(String username, String password, String salt, String plainPassword) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setSalt(salt);
        user.setPlainPassword(plainPassword);
        return user;
    }
}
